package com.mooc.lib_common;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.google.android.material.button.MaterialButton;

/**
 * @ClassName: EmptyView$
 * @Description: java类作用描述
 * @Author: 魏靳元
 * @CreateDate: 2022/8/17 15:03
 * @UpdateRemark: 更新内容
 * @Version: 1.0
 */
public class EmptyView extends LinearLayout {


    private ImageView emptyIcon;
    private TextView emptyText;
    private MaterialButton emptyAction;

    public EmptyView(@NonNull Context context) {
        this(context, null);
    }

    public EmptyView(@NonNull Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public EmptyView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        setOrientation(VERTICAL);
        setGravity(Gravity.CENTER);
        LayoutInflater.from(context).inflate(R.layout.layout_empty_view, this, true);

//        android:orientation="vertical"
//        android:gravity="center"
//        android:layout_gravity="center"
        emptyIcon = (ImageView) findViewById(R.id.empty_icon);
        emptyText = (TextView) findViewById(R.id.empty_text);
        emptyAction = (MaterialButton) findViewById(R.id.empty_action);
    }

    public void setEmptyIcon(@DrawableRes int iconRes){
        emptyIcon.setImageResource(iconRes);
    }
    public void setEmptyText(String text){
        if(TextUtils.isEmpty(text)){
            emptyText.setVisibility(GONE);
        }else {
            emptyText.setText(text);
            emptyText.setVisibility(VISIBLE);
        }
    }

    public void setEmptyAction(String text, View.OnClickListener listener){
        if(TextUtils.isEmpty(text)){
            emptyAction.setVisibility(GONE);
        }else {
            emptyAction.setText(text);
            emptyAction.setVisibility(VISIBLE);
            emptyAction.setOnClickListener(listener);
        }
    }


}
